<template>
  <div>
    <a-space>
      <a-select
        :value="values"
        optionFilterProp="label"
        show-search
        placeholder=""
        style="width: 200px"
        @change="handerChange"

      >
        <a-select-option
          v-for="item in options"
          :key="item.value"
          :value="item.value"
          :label="item.label"
        >{{item.label}}</a-select-option>
      </a-select>
      <a-popconfirm placement="bottomLeft" ok-text="确定" cancel-text="取消" @confirm="confirm">
        <template #title>
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="24">
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="名称">
                    <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="简称">
                    <a-input placeholder="请输入简称" v-model="queryParam.simpleName"></a-input>
                  </a-form-item>
                </a-col>
                <template v-if="toggleSearchStatus">
                  <a-col :xl="6" :lg="7" :md="8" :sm="24">
                    <a-form-item label="状态">
                      <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status"/>
                    </a-form-item>
                  </a-col>
                </template>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <!-- 查询区域-END -->
          <!-- table区域-begin -->
          <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
              <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
              <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>
            <a-table
              ref="table"
              size="middle"
              :scroll="{x:true}"
              bordered
              rowKey="id"
              :columns="columns"
              :dataSource="dataSource"
              :pagination="ipagination"
              :loading="loading"
              :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: 'radio'}"
              class="j-table-force-nowrap"
              @change="handleTableChange">

            </a-table>
          </div>
        </template>
        <div style='width:50px;height: auto;'><antd-icon type="search-o" style="font-size: 17px;" /></div>

<!--        <a-button>BL</a-button>-->
      </a-popconfirm>
    </a-space>
  </div>
</template>

<script>
import Vue from 'vue'
import { AntDesignOutline, DashboardOutline, TwitterOutline,SearchOutline } from '@ant-design/icons';
import AntdIcon from '@ant-design/icons-vue';
AntdIcon.add(AntDesignOutline, DashboardOutline,SearchOutline);
Vue.use(AntdIcon)


import ErpLocationList from '@/views/modules/location/ErpLocationList'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import { getAction } from '@api/manage'
import { ajaxGetDictItems } from '@api/api'

export default {
  name: 'TslErpCustomer',
  describes: 'Customer',
  props:{
    value:{
      type: String,
      required: false,
      default: ''
    },
    rowData:{
      type: Object,
      required: false,
    }
    // list: {
    //   type: Array,
    //   required: true
    // },
    // currentStatus: {
    //   type: Number,
    //   default: 0,
    //   required: false
    // }
  },
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    ErpLocationList
  },
  data() {
    return {
      values: this.value,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'名称',
          align:"center",
          dataIndex: 'name'
        },
        {
          title:'简称',
          align:"center",
          dataIndex: 'simpleName'
        },
        {
          title:'联系人',
          align:"center",
          dataIndex: 'contact'
        },
        {
          title:'联系电话',
          align:"center",
          dataIndex: 'telephone'
        },
        {
          title:'地址',
          align:"center",
          dataIndex: 'address'
        },
        {
          title:'客户分类',
          align:"center",
          dataIndex: 'cl_dictText'
        },
        {
          title:'品牌',
          align:"center",
          dataIndex: 'brand_dictText'
        },
        {
          title:'国家',
          align:"center",
          dataIndex: 'countryId_dictText'
        },
        {
          title:'所属洲',
          align:"center",
          dataIndex: 'continent'
        },
        {
          title:'销售区域',
          align:"center",
          dataIndex: 'salesArea'
        },
        {
          title:'客户类型',
          align:"center",
          dataIndex: 'type_dictText'
        },
        {
          title:'客户类别',
          align:"center",
          dataIndex: 'category_dictText'
        },
        {
          title:'开发时间',
          align:"center",
          dataIndex: 'deDate',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'业务员',
          align:"center",
          dataIndex: 'salesman_dictText'
        },
        {
          title:'状态',
          align:"center",
          dataIndex: 'status_dictText'
        },

      ],
      statusColorMap: {
        '启用': 'green',
        '停用': 'red'
      },
      url: {
        list: "/base/erpCustomer/list",
        delete: "/base/erpCustomer/delete",
        deleteBatch: "/base/erpCustomer/deleteBatch",
        exportXlsUrl: "/base/erpCustomer/exportXls",
        importExcelUrl: "base/erpCustomer/importExcel",
      },
      dictOptions:{},
      superFieldList:[],
      list1:[],
      options:[
        { value: 'jack', label: 'Jack' },
        { value: 'lucy', label: 'Lucy' },
        { value: 'tom', label: 'Tom' },
      ]

    }
  },
  created() {

  },
  mounted() {
    this.loadDictData()
    // console.log('传过来的值',this.value)
  },
  computed: {

  },
  watch:{
    value: function(newval,oldval){
      console.log('新的值',newval)
      this.values = newval
    }
  },
  methods:{
    loadDictData(){
      ajaxGetDictItems('erp_customer,name,id', null).then((res) => {
        if (res.success) {
          this.options = res.result
          // console.log('传过来的值',this.value)
        }
      })
    },
    confirm(){
      if(this.selectionRows.length > 0){
        const val = this.selectedRowKeys[0];
        const selectRow = this.selectionRows[0]
        console.log(selectRow)
        this.values = val
        this.$emit('input', val)
        this.callback(this.value)
      }
      this.onClearSelected()
    },
    handerChange(value,option){
      // console.log(value)
      this.values = value
      console.log(this.values)
      this.$emit('input', value)
      this.$emit('handlerok', value)
      this.callback(value)
    },
    callback(value){
      this.$emit('handlerOk',{
                    val: value
                  });
    },
    // getLocationInfo(value){
    //   const { row } = this.rowData
    //   const param = {id: value}
    //   getAction('/base/erpLocation/queryInfoById',param).then(res=>{
    //       if (res.success) {
    //         // 向外传递
    //         this.$emit('handlerOk',{
    //           result: res.result,
    //           row: row
    //         });
    //       }
    //   })
    // },
    add() {
      this.showModal();
    },
    showModal() {
      this.visible = true;
      this.queryParam = { procurementType: this.procurementType }
      this.loadData();
    },
    initDictConfig(){
    },
    getSuperFieldList(){
      let fieldList=[];
      // fieldList.push({type:'string',value:'wareHouseId',text:'仓库',dictCode:"erp_warehouse,name,id"})
      fieldList.push({type:'string',value:'code',text:'库位编号',dictCode:''})
      fieldList.push({type:'string',value:'name',text:'库位名称',dictCode:''})
      fieldList.push({type:'string',value:'status',text:'状态',dictCode:'erp_status'})
      this.superFieldList = fieldList
    },
    handleCancel () {
      this.close()
    },
    handleOk () {
      this.$emit('handlerOk',this.selectionRows[0]);
      this.close();
      // console.log(this.selectionRows[0])
    },
    close() {
      // this.searchReset(false);
      this.queryParam = {}
      this.selectedRowKeys = []
      this.selectionRows = []
      this.visible = false;
    },
  }
}
</script>

<style scoped>
/* 覆盖Dropdown菜单项在悬停时的背景颜色 */
.ant-dropdown-menu-item:hover,
.ant-dropdown-menu-submenu-title:hover {
  background-color: inherit; /* 或者设置为初始背景色 */
}
</style>